var transitionEndSetup=false;
function doShowTextBar(){try{
	var dm=document.querySelector("#domain");
	var tf=document.querySelector("#title-float");
	var tit=document.querySelector("#title");
	
	tf.style.width="-moz-calc( 100% - 246px )";
	tf.style.overflow="visible";
	dm.style.left=(dm.offsetLeft)+"px";
	dm.style.top=0+"px";
	dm.style.display="block";
	dm.style.position="absolute";
	dm.style.fontSize=10+"px";
	dm.style.width=dm.offsetWidth+"px";
	tit.style.display="none";
	
	if(!transitionEndSetup){
		dm.addEventListener("transitionend",function(evt){
			if(this.style.top=="-1px"){
				this.style.width="-moz-calc( 100% - 196px )";
			}
		},true);
		transitionEndSetup=true;
	}
	
	dm.style.left=160+"px";
	dm.style.top=(-1)+"px";
	dm.style.height=13+"px";
	dm.style.maxWidth="none";
	dm.style.width=(tf.offsetWidth-196)+"px";
}catch(e){trace(e);}}

function doHideTextBar(){try{
	var dm=document.querySelector("#domain");
	var tf=document.querySelector("#title-float");
	var tit=document.querySelector("#title");
	tf.style.width="";
	dm.style.position="";
	dm.style.display="";
	dm.style.left="";
	dm.style.top="";
	dm.style.maxWidth="";
	dm.style.width="";
	dm.style.height="";
	dm.style.fontSize="";
	tit.style.display="";
}catch(e){trace(e);}}

function expandTextBar(){try{
	if(glbDomainInputIsOpen)
		return;
	
	glbDomainInputIsOpen=true;
	doShowTextBar();
	var dm=document.querySelector("#domain");
	dm.textContent="";
	var inp=document.createElement("input");
	inp.type="text";
	inp.id="domain-input";
	
	inp.onclick=function(evt){
		evt.stopPropagation();
	};
	
	inp.onblur=onHideAddress;
	dm.appendChild(inp);
	
	glbDomainInputElement=inp;
	inp.focus();
	return inp;
}catch(e){trace(e);}}

function onShowAddress(){try{
	var inp=expandTextBar();

	inp.onkeydown=function(evt){
		if(evt.keyCode==13){
			if(! (/^[a-z]+\:/i).exec(this.value) )
				this.value="http://"+this.value;
			
			tabs[activeTab].tab.contentWindow.location=this.value;
			onHideAddress.call(this);
		}
	}

	inp.value=tabs[activeTab].tab.contentWindow.location.href;
	inp.select();
}catch(e){trace(e);}}

function onShowSearch(){try{
	var inp=expandTextBar();
	
	inp.onkeydown=function(evt){
		if(evt.keyCode==13){
			tabs[activeTab].tab.contentWindow.location="https://encrypted.google.com/search?hl=en&q="+this.value;
			onHideAddress.call(this);
		}
	};

	inp.value="Google Search";
	inp.select();
}catch(e){trace(e);}}

function onHideAddress(){try{
	if(!glbDomainInputIsOpen)
		return;
		
	glbDomainInputElement.parentNode.removeChild(this);
	doHideTextBar();
	document.querySelector("#domain").textContent=tabs[activeTab].lastDomain;
	glbDomainInputIsOpen=false;
}catch(e){trace(e);}}